<?php

function getSum($num=100){

	$total = 0;

	for ($i=0; $i <= $num ; $i++) { 
		$total +=$i;
	}

	return $total;
}
/**
 * [FormatSize 存储单位转位]
 * @param [type] $size [字节数]
 */
function Fsize($size)
{
	if($size<1024){
		return $size."b";
	}elseif($size<pow(1024,2)){
		return round($size/pow(1024,1),2)."kb";
	}elseif($size<pow(1024,3)){
		return round($size/pow(1024,2),2)."mb";
	}elseif($size<pow(1024,4)){
		return round($size/pow(1024,3),2)."gb";
	}else{
		return round($size/pow(1024,4),2)."tb";
	}
}
/**
 * [Ftime 时间格式化]
 * @param [type] $time [时间戳]
 */
function Ftime($time=null)
{
	if(!$time){
		return "现在";
	}
	$diff = time()-$time;
	if($diff<60){
		return "刚刚";
	}elseif ($diff<3600) {
		return floor($diff/60)."分钟之前";
	}elseif ($diff<86400) {
		return floor($diff/3600)."小时之前";
	}elseif ($diff<(86400*7)) {
		return floor($diff/86400)."天之前";
	}else{
		return date("Y-m-d H:i:s",$time);
	}
}

function getRandNum($num=7)
{
	$arr = [];

	for ($i=0; $i < $num ; $i++) { 

		$a = mt_rand(1,47);

		$is = true;

		for ($j=0; $j <count($arr) ; $j++) { 
			if($arr[$j]==$a){
				$is = false;
			}
		}

		if($is){
			$arr[] = $a;
		}else{
			$i--;
		}
	}

	return $arr;
}
/**
 * [getRandStr 实现产生指定位数的随机字符串]
 * @param  integer $num [位数]
 * @return [type]       [随机字符串]
 */
function getRandStr($num=16)
{
	$str = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890";

	$temp = "";

	for ($i=0; $i <$num ; $i++) { 
		$temp .= $str[mt_rand(0,strlen($str)-1)];
	}
	return $temp;
}

function getFreight($weight=null)
{
	if($weight<0){
		return "输入有错误";
	}
	if(!$weight){
		return 10;
	}
	$weight = ceil($weight);

	$price = 10 + ($weight-1)*5;

	return $price;
}
/**
 * [getSuffix 获得文件后缀]
 * @param  [type] $fileName [description]
 * @return [type]           [description]
 */
function getSuffix($fileName)
{
	$arr = explode('.', $fileName);

	return end($arr);
}

// $arr = [['name'=>'小明','class'=>'php01','score'=>'80'],['name'=>'小红','class'=>'php01','score'=>'70'],['name'=>'小花','class'=>'php02','score'=>'95'],['name'=>'小吕','class'=>'php01','score'=>'80'],['name'=>'小森','class'=>'php01','score'=>'60'],['name'=>'小磊','class'=>'php02','score'=>'70']];

// $temp =[];

// foreach ($arr as $k => $v) {
// 	$temp[$v['class']][] = $v;
// }

// var_dump($temp);